
var express = require('express');
var mysql=require("./db");
var router = express.Router();
router.get('/', function(req, res, next) {
    res.render("login",{title: '登陆'})
});
router.post("/log",function (req, res, next) {
    var name = req.body.uname;
    var password = req.body.upwd;
    mysql.query("SELECT * FROM  userinfo where UserName='"+name+"'AND `Password`='"+password+"'",function (rows) {
          if(rows.length){
               req.session.islogin=name;
               res.locals.islogin=name;
               res.cookie('islogin',res.locals.islogin,{maxAge:60000});
               return res.json({success:true, message:"登录成功", data:rows});
            }
            else
                {
                   return res.json({success:false, message:"登录失败", data:rows});
                }


      });


})
module.exports = router;
